<?php
class permission extends Model{

	private static $_view = array(/*{{{*/
		'View_PdesNoticeAction',
		'PdesNoticeAction',
		'View_BlankAction',
		'View_LoginAction',
		'View_PdesTaskListAction',
		'View_InfoGetAction',
		'View_P_InfoGetAction',
		'View_PdesListAction',
		'View_ProgrammeGetAction',
		'View_P_ProgrammeGetAction',
		'View_EpisodeGetAction',
		'View_P_EpisodeGetAction',
		'View_CastGetAction',
		'View_P_CastGetAction',
		'View_ChapterGetAction',
		'View_VideoGetAction',
		'View_P_VideoGetAction',
		'View_ImageGetAction',
		'View_P_ImageGetAction',
        'View_MisLogGetAction',
        'View_CastDictionaryAddAction',
        'View_CastDictionaryUpdateAction',
        'View_AutoPublishListAction',
	);/*}}}*/

	private static $_edit = array(/*{{{*/
		'View_BlankAction',
		'View_LoginAction',
		'View_PdesTaskListAction',
		'View_PdesSwitchAction',
		'View_InfoGetAction',
		'View_P_InfoGetAction',
		'View_PdesListAction',
		'View_ProgrammeAddAction',
		'View_ProgrammeUpdateAction',
		'View_ProgrammeSwitchAction',
		'View_ProgrammeGetAction',
		'View_P_ProgrammeGetAction',
		'View_EpisodeAddAction',
		'View_EpisodeUpdateAction',
		'View_EpisodeSwitchAction',
		'View_EpisodeGetAction',
		'View_P_EpisodeGetAction',
		'View_CastAddAction',
		'View_CastUpdateAction',
		'View_CastSwitchAction',
		'View_CastGetAction',
		'View_P_CastGetAction',
		'View_ChapterUpdateAction',
		'View_ChapterGetAction',
		'View_ChapterSwitchAction',
		'View_InfoAddressAddAction',
		'View_InfoAddressUpdateAction',
		'View_InfoRecipeAddAction',
		'View_InfoRecipeUpdateAction',
		'View_InfoSongAddAction',
		'View_InfoSongUpdateAction',
		'View_InfoSongMisUpdateAction',
		'View_InfoBiographyAddAction',
		'View_InfoBiographyUpdateAction',
		'View_InfoAwardAddAction',
		'View_InfoAwardUpdateAction',
		'View_InfoProductAddAction',
		'View_InfoProductUpdateAction',
		'View_InfoQnaAddAction',
		'View_InfoQnaUpdateAction',
		'View_InfoGetAction',
		'View_P_InfoGetAction',
		'View_InfoSwitchAction',
		'View_InfoGeneralAddAction',
		'View_InfoGeneralUpdateAction',
		'View_InfoPageantAddAction',
		'View_InfoPageantUpdateAction',
		'View_VideoUpdateAction',
		'View_VideoGetAction',
		'View_P_VideoGetAction',
		'View_ImageUpdateAction',
		'View_ImageGetAction',
		'View_P_ImageGetAction',
		'View_ImageSwitchAction',
		'View_VideoSwitchAction',
        'View_AutoPublishListAction',
		'BlankAction',
		'LoginAction',
		'PdesTaskListAction',
		'PdesSwitchAction',
		'InfoGetAction',
		'P_InfoGetAction',
		'PdesListAction',
		'ProgrammeAddAction',
		'ProgrammeUpdateAction',
		'ProgrammeSwitchAction',
		'ProgrammeGetAction',
		'P_ProgrammeGetAction',
		'EpisodeAddAction',
		'EpisodeUpdateAction',
		'EpisodeSwitchAction',
		'EpisodeGetAction',
		'P_EpisodeGetAction',
		'CastAddAction',
		'CastUpdateAction',
		'CastSwitchAction',
		'CastGetAction',
		'P_CastGetAction',
		'ChapterUpdateAction',
		'ChapterGetAction',
		'ChapterSwitchAction',
		'InfoAddressAddAction',
		'InfoAddressUpdateAction',
		'InfoRecipeAddAction',
		'InfoRecipeUpdateAction',
		'InfoSongAddAction',
		'InfoSongUpdateAction',
		'InfoSongMisUpdateAction',
		'InfoBiographyAddAction',
		'InfoBiographyUpdateAction',
		'InfoAwardAddAction',
		'InfoAwardUpdateAction',
		'InfoProductAddAction',
		'InfoProductUpdateAction',
		'InfoQnaAddAction',
		'InfoQnaUpdateAction',
		'P_InfoGetAction',
		'InfoSwitchAction',
		'InfoGeneralAddAction',
		'InfoGeneralUpdateAction',
		'InfoPageantAddAction',
		'InfoPageantUpdateAction',
		'VideoUpdateAction',
		'VideoGetAction',
		'P_VideoGetAction',
		'ImageUpdateAction',
		'ImageGetAction',
		'P_ImageGetAction',
		'ImageSwitchAction',
		'VideoSwitchAction',
        'MisLogGetAction',
        'CastDictionaryAddAction',
        'CastDictionaryUpdateAction',
        'AutoPublishListAction',
	);/*}}}*/

	private static $_proofread = array(/*{{{*/
		'PdesNoticeAction',
		'View_PdesNoticeAction',
		'View_ChapterUpdateAction', 'ChapterUpdateAction',
		'View_PdesListAction',
		'View_ProgrammeGetAction',
		'View_P_ProgrammeGetAction',
		'View_ProgrammeSwitchAction',
		'View_EpisodeGetAction',
		'View_P_EpisodeGetAction',
		'View_EpisodeSwitchAction',
		'View_CastGetAction',
		'View_CastSwitchAction',
		'View_ImageGetAction',
		'View_P_ImageGetAction',
		'View_ImageSwitchAction',
		'View_VideoGetAction',
		'View_P_VideoGetAction',
		'View_VideoSwitchAction',
		'View_InfoGetAction',
		'View_P_InfoGetAction',
		'View_InfoSwitchAction',
	);/*}}}*/

	private static $_liberal = array(/*{{{*/
		'PdesNoticeAction',
		'View_PdesNoticeAction',
		'View_PdesListAction', 'PdesListAction',
		'View_ChapterUpdateAction', 'ChapterUpdateAction',
		'View_ChapterGetAction', 'ChapterGetAction',
		'View_VideoGetAction', 'VideoGetAction','View_P_VideoGetAction', 'P_VideoGetAction', 'Liberal_ChapterGetAction',
		'Freelancer_ProgrammeGetAction',
	);/*}}}*/

	private static $_freelancer = array(
		'Freelancer_ProgrammeGetAction',
	);

	private static $_P = array();

	public static function initPermission(){
		self::$_P= array(
			'all'       => array_values(array_unique(array_merge(self::$_view,self::$_proofread,self::$_edit,self::$_liberal))),
			'proofread' => self::$_proofread,
			'edit'      => array_values(array_unique(array_merge(self::$_view,self::$_edit))),
			'liberal'   => self::$_liberal,
			'view'      => self::$_view,
			'freelancer'=> array_values(array_unique(array_merge(self::$_view,self::$_edit,self::$_freelancer))),
		);
	}
	public static function getPermssionNamesByActionObj(IAction $action){
		$all_group = array(
			'edit'=>false,
			'liberal'=>false,
			'proofread'=>false,
			'all'=>false,
			'view'=>false,
			'freelancer'=>false,
		);
		$action->setData('_g',$all_group);

		$class = get_class($action);

		$items['view']      = array( 'View_'.$class );
		$items['proofread'] = array( 'View_'.$class );
		$items['edit']      = array( 'View_'.$class, $class );
		$items['liberal']   = array( 'View_'.$class, $class );
		$items['freelancer']= array( 'View_'.$class, $class );

		if(isset($action->act) && ('edit'==$action->act || 'add'==$action->act)){
			$items['view']      = array( );
			$items['proofread'] = array( );
		}
		if($class!='PdesSwitchAction' && strpos($class,'SwitchAction')){
			if(!isset($_REQUEST['proof']) && !isset($_REQUEST['unpublish'])){
				$items['proofread'] = array();
			}else{
				$items['liberal']    = array();
				$items['freelancer'] = array();
				$items['edit']       = array();
			}
		}

		$items['all'] = array_values(array_unique(array_merge($items['view'], $items['edit'], $items['liberal'], $items['proofread'])));

		if(in_array($class, array('ProgrammeGetAction'))){
			$items['liberal'][] = 'Freelancer_'.$class;
			$items['freelancer'][] = 'Freelancer_'.$class;
		}

		if(in_array($class, array('ChapterGetAction'))){
			$items['proofread'][] = 'Liberal_'.$class;
			$items['liberal'][]   = 'Liberal_'.$class;
			$items['all'][]       = 'Liberal_'.$class;
		}

		return $items;
	}

	public static function getPermission(){
		return self::$_P;
	}
	public static function getTableName(){
		return 'permission';
	}


}
